package com.lucky.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description 模拟redis 缓存
 * @Author Jalyson
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2019/6/26
 */
public class RedisCache {
    /** logger */
    private static final Logger LOGGER = LoggerFactory.getLogger(RedisCache.class);

    private static Map<String, Object> cacheMap;

    /**
     *
     * @param key 缓存key
     * @param user 用户
     */
    public static void cacheData(String key, Object user) {
        if (cacheMap == null) {
            cacheMap = new ConcurrentHashMap<>();
        }
        cacheMap.put(key, user);
    }

    /**
     * 获取缓存数据
     * @param key key
     * @return
     */
    public static Object getData(String key) {
        if (cacheMap == null || key == null) {
            return null;
        }
        return cacheMap.get(key);
    }

    /**
     * 删除缓存数据
     * @param key key
     * @return
     */
    public static Boolean remove(String key) {
        if (cacheMap == null || key == null) {
            return false;
        }
        return cacheMap.remove(key) != null;
    }

}
